package com.cyanite.playlv2.maps;

import com.cyanite.playlv2api.types.Tip;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import android.graphics.drawable.Drawable;

public class TipItemizedOverlay extends BaseGroupItemizedOverlay<Tip> {

    public TipItemizedOverlay(Drawable defaultMarker) {
        super(defaultMarker);
    }

    @Override
    protected OverlayItem createItem(int i) {
        Tip tip = (Tip)group.get(i);
        int lat = (int)(Double.parseDouble(tip.getVenue().getGeolat()) * 1E6);
        int lng = (int)(Double.parseDouble(tip.getVenue().getGeolong()) * 1E6);
        GeoPoint point = new GeoPoint(lat, lng);
        return new TipOverlayItem(point, tip);
    }

    @Override
    public boolean onTap(GeoPoint p, MapView mapView) {
        mapView.getController().animateTo(p);
        return super.onTap(p, mapView);
    }

    public static class TipOverlayItem extends OverlayItem {

        private Tip mTip;

        public TipOverlayItem(GeoPoint point, Tip tip) {
            super(point, tip.getVenue().getName(), tip.getVenue().getAddress());
            mTip = tip;
        }

        public Tip getTip() {
            return mTip;
        }
    }

}
